<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>航班查询</title>
    <script type="text/javascript" src="js/jquery-1.8.3.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $.get("Flight/find", function (list) {
                forlist(list)
            });
            $("[ name ='select']").click(function () {
                var flight_date = $("[name = 'flight_date']").val();
                var city_name = $("[name = 'city_name']").val();
                var landcity = $("[name = 'landcity']").val();
                $.get("Flight/find", {
                    "flight_date": flight_date,
                    "city_name": city_name,
                    "landcity": landcity
                }, function (list) {
                    forlist(list)
                })
        });
        });
        $(document).on("click","[title = 'query']", function () {
            var id =$(this).attr("name");
            alert(id);
            $.get("ticket/find",{"flight_id" :id},function (list) {
                $("[title = "+id+"]").empty();
                for (let i = 0; i < list.length; i++) {
                    $("<tr> " +
                        "<td>" + list[i].sell_company + "<td>" +
                        "<td>" + list[i].ticket_price + "<td>" +
                        "<tr>").appendTo("[title ="+id+" ]")
                }
            })
        });
        function forlist(list) {
            $("#tbody").empty();
            for (let i = 0; i < list.length; i++) {
                $("<tr>" +
                    "<td>" + list[i].airline + list[i].flight_code + "/" + list[i].type + "</td>" +
                    "<td>" + list[i].take_time + "-" + list[i].landing_time + "</td>" +
                    "<td>" + list[i].airport_name + list[i].landairports + "</td>" +
                    "<td>" + list[i].flight_time + "</td>" +
                    "<td>" + list[i].stop_airport + "</td>" +
                    "<td>" + list[i].reference + "</td>" +
                    "<td><a title='query' name='"+list[i].id+"'>查看购票</a></td></tr><tr title='"+list[i].id+"'></tr>").appendTo("#tbody");
            }
        }

    </script>
</head>
<body>
<h1 style="text-align: center">航班查询</h1>
<div style="text-align: center">
日期 <input type="text" name="flight_date" />
城市 从 <input type="text" name="city_name" /> 到 <input type="text" name="landcity" />
<input type="button" value="搜索" name="select" />
</div>
<form>
    <table border="1px" style="margin: 0 auto; text-align: center;">
        <thead>
        <tr>
            <td>航空公司/航班机型</td>
            <td>起降时间</td>
            <td>机场</td>
            <td>飞行时长</td>
            <td>经停</td>
            <td>参考报价</td>
            <td>操作</td>
        </tr>
        </thead>
        <tbody id="tbody">
        </tbody>

    </table>
</form>
</body>
</html>